package com.zhentao.product.controller;

import com.zhentao.nlz.project.dto.TDeptDto;
import com.zhentao.nlz.project.product.TDept;
import com.zhentao.product.service.TDeptService;
import com.zhentao.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("tDept")
public class TDeptController {
    @Autowired
    private TDeptService tDeptService;
//    查询所有的DeptParentId=0数据
    @GetMapping("deptByParentId")
    public Result deptByParentId(TDeptDto deptDto){
        return tDeptService.deptByParentId(deptDto);
    }
//    根据父id查询所有的子id的数据
    @GetMapping("deptChildrenById")
    public Result deptChildrenById(@RequestParam("parentId") Integer parentId){
        System.out.println(parentId);
        return tDeptService.deptChildrenById(parentId);
    }
//    根据id进行查询单个数据信息
    @GetMapping("deptById")
    public Result deptById(@RequestParam("id") Integer id){
        return tDeptService.deptById(id);
    }
//    根据id进行修改数据
    @PostMapping("deptUpdate")
    public Result deptUpdate(TDept dept){
        return tDeptService.deptUpdate(dept);
    }
//    根据id进行删除数据
    @PostMapping("deptDelete")
    public Result deptDeleteByDeptId(TDept dept){
        return tDeptService.deptDeleteByDeptId(dept);
    }
//    添加部门信息
    @PostMapping("deptSave")
    public Result deptSave(TDept dept){
        return tDeptService.deptSave(dept);
    }
//    删除部门一级部门下的所有部门
    @PostMapping("deptDelAll")
    public Result deptDelAll(TDept dept){
        return tDeptService.deptDelAll(dept);
    }
    @GetMapping("list")
    public Result list(){
        return Result.success(tDeptService.list());
    }
//    根据租户id
    @GetMapping("deptByTenantId")
    public Result deptByTenantId(@RequestParam("tenantId") Integer tenantId){
        return tDeptService.deptByTenantId(tenantId);
    }
    @GetMapping("deptListByTenantId")
    public List<TDept> deptListByTenantId(@RequestParam("id") Integer tenantId){
        return tDeptService.deptListByTenantId(tenantId);
    }

    @GetMapping("getDeptId")
    public Result getDeptId(@RequestParam("id")Integer id){
        return Result.success(tDeptService.getById(id));
    }


}
